package org.soenea.doitall.domain.model.group.data;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.dsrg.soenea.service.threadLocal.DbRegistry;

public class GroupFinder {
	public static final String BASE_NAME = "group";
	public static final String TABLE = DbRegistry.getTablePrefix()+BASE_NAME;

	public static String SELECT_BY_ID = "SELECT g.groupId,g.version,g.groupName,g.description FROM " + TABLE + " AS g WHERE g.groupId=?;";
	public static String SELECT_ALL = "SELECT g.groupId,g.version,g.groupName,g.description FROM " + TABLE + " AS g;";
	
	public static ResultSet findAll() throws SQLException {
		PreparedStatement ps = DbRegistry.getDbConnection().prepareStatement(SELECT_ALL);
		return ps.executeQuery();
	}
	
	public static ResultSet find(long id) throws SQLException {
		PreparedStatement ps = DbRegistry.getDbConnection().prepareStatement(SELECT_BY_ID);
		ps.setLong(1, id);
		return ps.executeQuery();
	}
}
